package com.yf.exam.modules.sys.system.controller;


import com.yf.exam.core.api.ApiRest;
import com.yf.exam.core.api.ResultPage;
import com.yf.exam.core.api.controller.BaseController;
import com.yf.exam.modules.sys.system.entity.SysLog;
import com.yf.exam.modules.sys.system.service.SysLogService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 肖守凯
 * @since 2020-11-11
 */
@Controller
@RequestMapping("/exam/api/sys/sysLog")
public class SysLogController extends BaseController {

    @Autowired
    private SysLogService sysLogService;

    @Value("${server.port}")
    private String port ;

    /**
     * 分页查询SysLog
     *
     * @param page   页码
     * @param limit  查几条
     * @param sysLog 前端传进的参数
     * @return 返回统一分页信息
     */
    @RequestMapping(value = "/findSysLogByPage")
    @ResponseBody
    public ResultPage<SysLog> findSysLogByPage(Integer page, Integer limit, SysLog sysLog,String startTime,String endTime) {

        System.out.println("sysLog:"+sysLog);


        return sysLogService.findSysLogByPage(page, limit, sysLog,startTime,endTime);


    }

    /**
     * 添加SysLog
     *
     * @param sysLog 前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "/addSysLog")
    @ResponseBody
    public ApiRest saveSysLog(SysLog sysLog) {

        if (sysLogService.addSysLog(sysLog)) {
            return super.success();
        }

        return super.failure();
    }

    /**
     * 编辑SysLog
     *
     * @param sysLog 前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "/editSysLog")
    @ResponseBody
    public ApiRest editSysLog(SysLog sysLog) {
        if (sysLogService.editSysLog(sysLog)) {
            return super.success();
        }


        return super.failure();
    }


    /**
     * 删除一条SysLog
     *
     * @param id 前端传进的ID
     * @return 返回统一信息
     */
    @RequestMapping(value = "/delSysLog")
    @ResponseBody
    public ApiRest delSysLog(Integer id) {
        if (sysLogService.delSysLog(id)) {
            return super.success();
        }


        return super.failure();
    }



    /**
     * 获取当前端口号
     */

    @RequestMapping(value = "/getPort")
    @ResponseBody
    public ApiRest getPort() {

        return super.failure(port);
    }

}
